const fs = require('fs')
const path = require('path')

function deleteFolderRecursive(folderPath) {
    if (fs.existsSync(folderPath)) {
        fs.readdirSync(folderPath).forEach((file) => {
            const curPath = path.join(folderPath, file)
            if (fs.lstatSync(curPath).isDirectory()) {
                deleteFolderRecursive(curPath)
            } else {
                fs.unlinkSync(curPath)
            }
        })
        try {
            fs.rmdirSync(folderPath)
        } catch (error) {
            console.log('delete error', error)
        }
        console.log(`Folder ${folderPath} deleted successfully.`)
    } else {
        console.log(`Folder ${folderPath} does not exist.`)
    }
}

const folderPath = 'log_box/project-logs/undefined'
setTimeout(() => {
    // temp delete folder
    deleteFolderRecursive(folderPath)
}, 2000);